<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="100px">
      <el-form-item label="车型类型" prop="itemTypeId">
        <el-select v-model="queryParams.itemTypeId" placeholder="请选择车型类型" clearable>
          <el-option
          v-for="dict in carOptions"
          :key="dict.itemTypeId"
          :label="dict.itemTypeName"
          :value="dict.itemTypeId"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="工序类型" prop="processCode">
        <el-input
          v-model="queryParams.processCode"
          placeholder="请输入工序编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="processList">
      <el-table-column label="工序编码" align="center" prop="processCode" />
      <el-table-column label="工序名称" align="center" prop="processName" :show-overflow-tooltip="true"/>
      <el-table-column label="车型" align="center" prop="itemTypeName" :show-overflow-tooltip="true"/>
      <el-table-column label="作业指导地址" align="center" prop="animation" :show-overflow-tooltip="true"/>
      <el-table-column label="视频流地址" align="center" prop="video" :show-overflow-tooltip="true"/>
      <el-table-column label="作业指导文档" align="center" prop="operationManual" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <el-link v-if="scope.row.operationManual"  type="primary" :href="scope.row.operationManual" target="_blank">查看文档</el-link>
        </template>
      </el-table-column>
      <el-table-column label="是否启用" align="center" prop="enableFlag">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.enableFlag"/>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true"/>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            v-hasPermi="['mes:pro:process:list']"
            @click="instructions(scope.row)"
            >查看作业指导</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            v-hasPermi="['mes:pro:process:list']"
            @click="processAnimation(scope.row)"
            >查看工序动画</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listProcess, getProcess, delProcess, addProcess, updateProcess } from "@/api/mes/pro/process";
import { getListProduct } from "@/api/mes/sales/salesPlan";
export default {
  name: "productionGuidance",
  dicts: ['sys_yes_no'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 生产工序表格数据
      processList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        itemTypeId: null,
      },
      carOptions: [],
    };
  },
  created() {
    this.getList();
    getListProduct().then(res=>{
      this.carOptions = res.data
    })
  },
  methods: {
    /** 查询生产工序列表 */
    getList() {
      this.loading = true;
      listProcess(this.queryParams).then(response => {
        this.processList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 修改按钮操作 */
    instructions(row) {
      window.open(row.animation, '_blank');
      console.log(row);
    },
    /** 删除按钮操作 */
    processAnimation(row) {
      if(row.video){
        window.open(row.video, '_blank');
      }else{
        this.$message.error("视频流地址为空");
      }
      console.log(row);
    }
  }
};
</script>
